﻿using HealthcareSystem.API.Read.Application.Command;
using HealthcareSystem.API.Read.Application.Command.ChronicDisease;
using HealthcareSystem.API.Read.Application.Command.ChronicSign;
using HealthcareSystem.API.Read.Application.Command.Indicator;
using HealthcareSystem.API.Read.Application.Command.KnowledgeCommand;
using HealthcareSystem.API.Read.Application.Command.Metrics;
using HealthcareSystem.API.Read.Application.Command.Team;
using HealthcareSystem.API.Read.DTO;
using HealthcareSystem.API.Read.DTO.Indicator;
using HealthcareSystem.API.Read.DTO.KnowledgeShowDto;
using HealthcareSystem.API.Read.DTO.Team;
using HealthcareSystem.Domain;
using HealthcareSystem.Domain.BasicSettings.Metrics;
using HealthcareSystem.Domain.ChronicDiseaseManagement;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using WeekExam.PassPort.ErrorCode;
using HealthcareSystem.API.Read.Application.Command.Element.ElementCommand;
using HealthcareSystem.API.Read.DTO.Element;
using Azure.Core;
using HealthcareSystem.API.Read.Application.Command.Followup;
using HealthcareSystem.API.Read.DTO.Followup;
using HealthcareSystem.API.Read.Application.Command.Disease;
using HealthcareSystem.API.Read.DTO.Disease;
using HealthcareSystem.API.Read.DTO.ChronicDTO;
using HealthcareSystem.API.Read.DTO.Equipment;
using HealthcareSystem.API.Read.Application.Command.Equipment;
using HealthcareSystem.Domain.BasicSettings.Team;

namespace HealthcareSystem.API.Read.Controllers
{
    /// <summary>
    /// 控制器--(读)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagerController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<ManagerController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public ManagerController(ILogger<ManagerController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }


        /// <summary>
        /// 日志记录
        /// </summary>
        /// <returns>返回方法</returns>
        [HttpGet]
        public IActionResult TextFilc()
        {
            try
            {
                logger.LogInformation("测试了一下日志记录报错");
                int num = int.Parse("ABC");
            }
            catch (Exception ex)
            {
                logger.LogError("测试日志记录报错!" + ex.Message);
                throw;
            }
            return Ok("完成");
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="cmd">处理</param>
        /// <returns>返回方法</returns>
        [HttpPost]
        public async Task<ApiResult<Login>> Login(LoginCommand cmd)
        {
            try
            {
                logger.LogInformation("用户进行登录操作");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("登录报错!" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 居民档案列表
        /// </summary>
        /// <param name="cmd">处理</param>
        /// <returns>返回方法</returns>
        [HttpGet]
        public async Task<ApiResult<ApiPaging<List<RecordDTO>>>> RecordList([FromQuery] RecordCommand cmd)
        {
            try
            {
                logger.LogInformation("居民档案列表操作");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("获取居民档案列表出错!" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 获取健康宣教列表
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<HealthEducation>>>> HealthEducationList([FromQuery] HealthEducationShowCommand command)
        {
            try
            {
                return mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 指标显示方法
        /// </summary>
        /// <param name="command">指标请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<MetricsDTO>>>> MetricsShow([FromQuery] MetricsCommand command)
        {
            try
            {
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        /// <summary>
        /// 指标分类显示
        /// </summary>
        /// <param name="command">请求命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<List<MetricsClass>>> MetricsClassShow()
        {
            try
            {
                MetricsClassCommand command = new MetricsClassCommand();
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        /// <summary>
        /// 我的知识显示
        /// </summary>
        /// <param name="request">返回值</param>
        /// <param name="cancellationToken"></param>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<KnowledgeDto>>>> KnowledgeShow([FromQuery] ShowKnowledgeCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 健康监测记录列表
        /// </summary>
        /// <param name="command">请求命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<List<HealthMonitoring>>> HealthMonitoringList()
        {
            try
            {
                HealthMonitoringShowCommand command = new HealthMonitoringShowCommand();
                return mediator.Send(command);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// 机构树形
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<List<InstitutionDTO>>> InstitutionTree()
        {
            InstitutionCommand command = new InstitutionCommand();
            return mediator.Send(command);
        }

        /// <summary>
        /// 机构查询页面
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>取消</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<Institution>>>> InstitutionShow([FromQuery] QueryInstitutionCommand command)
        {
            return mediator.Send(command);
        }

        /// <summary>
        /// 元素显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<ShowElementDto>>>> ElementShow([FromQuery] ShowElementCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 查询签约信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回签约信息请求结果</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<CSignDTO>>>> ShowCsign([FromQuery] ShowCsignCommad request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 元素下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<List<SelectElementDto>>> SelectElement([FromQuery] SelectElementCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 团队显示方法
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<TeamTableDTO>>>> TeamTableShow([FromQuery] TeamQueryCommand command)
        {
            return mediator.Send(command);
        }

        /// <summary>
        /// 表单显示处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<List<ShowFollowupDto>>> FollowShow([FromQuery] ShowFormUpCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 表单类型下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<List<SelectFollowDto>>> SelectFollow()
        {
            SelectFollowCommand request = new SelectFollowCommand();
            return mediator.Send(request);
        }

        /// <summary>
        /// 病种下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<List<SelectListofdiseasesDto>>> ListofdiseasesSelect()
        {
            SelectListofdiseasesCommand request = new SelectListofdiseasesCommand();
            return mediator.Send(request);
        }

        /// <summary>
        /// 病种显示列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<ShowDiseasemanageDto>>>> DiseasemanagShow([FromQuery] ShowDiseaseCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取健康报告列表
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回健康报告列表结果</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<HealthReportDTO>>>> HealthReportQuery([FromQuery] HealthReportListCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 设备分页显示方法
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<EquipmentDTO>>>> EquipmentShow([FromQuery] EquipmentQueryCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<List<Login>>> UserInfoList()
        {
            UserInfoListCommand command = new UserInfoListCommand();
            return mediator.Send(command);
        }
        /// <summary>
        /// 慢病数据列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<ChronicDataDTO>>>> ChronicDataList([FromQuery] ChronicDataShowCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 查询单个签约信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回查询单个签约信息请求结果</returns>
        [HttpGet]
        public Task<ApiResult<List<Record>>> ShowRecordCsign([FromQuery]ShowCSignOneCommad request)
        {
            return mediator.Send(request);  
        }
        /// <summary>
        /// 随访管理列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<List<FollowupDTO>>>> FollowupManagementShow([FromQuery] FollowupManagementShowCommand command)
        {
            return mediator.Send(command);
        }
    }
}
